import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/home/home.vue'

Vue.use(VueRouter)

const routes = [{
		path: '/',
		name: 'HomeView',
		meta: {
			title: '主页'
		},
		component: HomeView,
		redirect: '/instrument',
		children:[
			{
				path: '/order',
				name: 'OrderList',
				meta: {
					title: '订单列表'
				},
				component: () => import("@/views/order/order.vue"),
			},
			{
				path: '/addQuality',
				name: 'addQuality',
				meta: {
					title: '商品列表'
				},
				component: () => import("@/views/addQuality/addQuality.vue"),
			},
			{
				path: '/project',
				name: 'ProjectList',
				meta: {
					title: '项目列表'
				},
				component: () => import("@/views/project/project.vue"),
			},
			{
				path: '/title',
				name: 'title',
				meta: {
					title: '项目列表'
				},
				component: () => import("@/views/Title/title.vue"),
			},
			{
				path: 'organization',
				name: 'organization',
				meta: {
					title: '纵横组织'
				},
				component: () => import("@/views/organization/organization.vue"),
			},
			{
				path: 'advertising',
				name: 'advertising',
				meta: {
					title: '广告管理'
				},
				component: () => import("@/views/advertising/advertising.vue"),
			},
			{
				path: 'advertisingUser',
				name: 'advertisingUser',
				meta: {
					title: '广告账户'
				},
				component: () => import("@/views/advertiSingUser/advertiSingUser.vue"),
			},
			{
				path: 'qualiFications',
				name: 'QualificationsInfo',
				meta: {
					title: '资质列表'
				},
				component: () => import("@/views/Qualifications/Qualifications.vue"),
			},
			{
				path: 'system',
				name: 'system',
				meta: {
					title: '系统账号'
				},
				component: () => import("@/views/System/system.vue"),
			},
			{
				path: 'Material',
				name: 'Material',
				meta: {
					title: '素材列表'
				},
				component: () => import("@/views/Material/Material.vue"),
			},
			
			{
				path: 'instrument',
				name: 'instrument',
				meta: {
					title: '仪表盘'
				},
				component: () => import("@/views/instrument/instrument.vue"),
			},
			{
			path: 'Forbidden',
				name: 'Forbidden',
				meta: {
					title: '封禁账号'
				},
				component: () => import("@/views/Forbidden/Forbidden.vue"),
			},
			{
			path: 'Forbidden',
				name: 'Forbidden',
				meta: {
					title: '封禁账号'
				},
				component: () => import("@/views/Forbidden/Forbidden.vue"),
			},
			{
				path: 'updateOrder',
				name: 'updateOrder',
				meta: {
					title: '修改订单信息'
				},
				component: () => import("@/views/updateOrder/updateOrder.vue"),
			},
			{	
				path: 'configuration',
				name: 'Configuration',
				meta: {
					title: '用户配置'
				},
				component: () => import("@/views/Configuration/Configuration.vue"),
			},
			{
				path: 'jurisdiction',
				name: 'jurisdiction',
				meta: {
					title: '投手管理'
				},
				component: () => import("@/views/jurisdiction/jurisdiction.vue"),
			},
		]
	},
	{
		path:'/login',
		name:'UserLogin',
		meta: {
			title: '登录'
		},
		component: () => import('@/views/Login/login.vue')
	}
]

const router = new VueRouter({
	mode: 'history',
	base: process.env.BASE_URL,
	routes
})

// router.beforeEach((to, from, next) => {
// 	//如果用户已经登录:直接放行
// 	if (window.sessionStorage.getItem("user") != null && to.path !== '/login') {
// 		if (!isLoadMenu) {
// 			generator();
// 			console.log(router.getRoutes(), "----先在的所有路由地址");
// 			isLoadMenu = true;
// 			next({
// 				...to,
// 				replace: true
// 			});
// 		} else {
// 			next();
// 		}
// 	} else { //没有登录
// 		if (to.path === '/login') { //直接登录页面：放行
// 			next()
// 		} else { //去其他页面：重定向到登录页面
// 			next('/login')
// 		}
// 	}
// });
router.beforeEach((to, from, next) => {
	//如果用户已经登录:直接放行
	if (window.sessionStorage.getItem("user") != null && to.path !== '/login') {
			next()
	} else {//没有登录
		if (to.path === '/login') {//直接登录页面：放行
			next()
		} else {//去其他页面：重定向到登录页面
			next('/login')
		}
	}
});



export default router